import {ActionTree, GetterTree, MutationTree} from 'vuex';
import Emitter from "@/utils/emitter";



interface stateType {
    [x: string]: any
}

const state = {
    device: "desktop",
    locale: navigator.language
}
const getters : GetterTree<any, any> = {
    device: (state: stateType) => state.device,
    locale: (state: stateType) => state.locale,
};
const mutations : MutationTree<any> = {
    toggleDevice: (state: stateType, device: any) => {
        state.device = device;
    },
    changeLocale: (state: stateType, lang) => {
        state.locale = lang;
    }
};
const actions : ActionTree<any, any> = {
    toggleDevice({ commit }, device) {
        commit("toggleDevice", device);
    },
    changeLocale({ commit }, lang) {
        const emitter = Emitter.shared().emitter;
        emitter.emit('change-language', lang)
        commit('changeLocale', lang);
    }
};
export default { state, getters, mutations, actions };
